package com.bbzn.device.client.service.impl;

import com.bbzn.device.client.config.OSSProperties;
import com.bbzn.device.client.service.OssService;
import com.bbzn.device.client.utils.OSSUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @Author: 曾俞钧
 * @Date : 2021/3/24 14:31
 * @Version 1.0
 */
@Service
@Slf4j
public class OssServiceImpl implements OssService {

    OSSUtil ossUtil = new OSSUtil();
    /**
     * SAAS 目前
     * @param file
     * @return
     * @throws Exception
     */
    @Override
    public String uploadHeadImg(MultipartFile file) throws Exception {

           String name= ossUtil.uploadImg(file);
           //加路径名
         String url = OSSProperties.ALIYUN_SAAS_URL+name;
         return  url;
    }

    /**
     * 删除资源
     * @param imgName
     * @return
     * @throws Exception
     */
    @Override
    public int delHeaderImg(String imgName) throws Exception {

        return ossUtil.deleteObject(imgName);
    }

    /**
     * 上传视频
     * @param file
     * @return
     * @throws Exception
     */
    @Override
    public String uploadVideo(MultipartFile file) throws Exception {
         String name = ossUtil.uploadVideo(file);

        return name;
    }

    @Override
    public String uploadExcel(MultipartFile file) throws Exception {
        String name = ossUtil.uploadExcel(file);
        String url = OSSProperties.ALIYUN_URL+"/"+name;
        return url;
    }

    @Override
    public String uploadFile(MultipartFile file) throws Exception {
        String name =  ossUtil.uploadFile2OSS(file.getInputStream(),file.getOriginalFilename());
        String url = OSSProperties.ALIYUN_SAAS_URL+name;
        return url;
    }

    @Override
    public List delListImg(List<String> list) throws Exception {
        return ossUtil.deleteObjects(list);
    }
}
